package com.zgscwjm.taobaphelper.xp;

import android.content.Context;
import android.os.Process;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zgscwjm.taobaphelper.auto.phoneBaseInfo;
import com.zgscwjm.taobaphelper.b.a;
import com.zgscwjm.taobaphelper.data.TestAccountBean;
import com.zgscwjm.taobaphelper.data.dataException;
import com.zgscwjm.taobaphelper.exutils.StringUtils;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ArrayUtils;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by fukunaka on 2017/3/16.
 */

public class DSSnapshotManager {

    public static String CMD_LOGIN_TAOBAO = "uiautomator runtest AutoRunner.jar -c dowork.SnapshotCraetor";
    public static String CMD_RESULT_OUTPUT = " uiautomator runtest AutoRunner.jar -c dowork.ResultOutput ";
    public static String CMD_NETFLOW_RECOVER = " uiautomator runtest AutoRunner.jar -c dowork.NetflowRecoverRunner ";
    public String tbDataDir = "/data/data/com.taobao.taobao";
    public String tbDipeDNSiDir = "/sdcard/com.taobao.mobile.dipeihttpdns";
    public String tbObbDir = "/sdcard/obb/com.taobao.taobao";
    public String tbPackageName = "com.taobao.taobao";
    public String tbSDCardDir = "/mnt/sdcard/Android/data/com.taobao.taobao";
    public String tbSdcardDpDir = "/sdcard/.com.taobao.dp";
    public String tbSharePrefsDir = (tbDataDir + "/shared_prefs");
    public String tbStorageDir = "/storage/emulated/0/.com.taobao.dp";
    public String tbStorageDir2 = "/storage/emulated/0/android/data/com.taobao.taobao";
    public String tbStorageRelativePath = "/files/storage";
    public Context mcontext;
    public String mGroupName;
    public String dataDir = "/data/data";
    public String snapDirName = "snaps";
    public String taobaoLibDir = "/data/app-lib/com.taobao.taobao*";
    public String taobaoLibDir2 = "/data/app-lib/taobao";
    public String tbHttpCdnDir = "/sdcard/com.taobao.taobaohttpdns";
    public String[] clearDir = new String[]{tbDataDir, tbSDCardDir, tbObbDir, tbSdcardDpDir, taobaoLibDir, taobaoLibDir2, tbStorageDir, tbStorageDir2, tbDipeDNSiDir, tbHttpCdnDir};
    public static DSSnapshotManager _instance = null;
    public static String fileDir = FileManager.filesDirPath;
    public static String accFile = (fileDir + "acc.txt");
    public static String backupFile = (fileDir + "backup.txt");
    public static String bssidFile = (fileDir + "bssid.txt");
    public static String recLogFile = (fileDir + "recoverLogs.txt");
    public static String nomisionFile = (fileDir + "nomission.txt");
    public static String tmpImeiFile = "/data/local/tmp/guid.txt";
    public static String finishNumFile = FileManager.finishNumPath;
    public static String snapsDir = (fileDir + "snaps");
    public static String startTsFile = (fileDir + "startTs.txt");
    public static String workResFile = (fileDir + "workred.txt");
    public static String storageDir = ("/data/local/tmp/storage");


    public static String[] tmpFile = new String[]{accFile, recLogFile, nomisionFile, tmpImeiFile, finishNumFile, snapsDir, backupFile, bssidFile, startTsFile, workResFile, storageDir};

    public class LockManager {
        Context context;
    }

    public DSSnapshotManager(Context context) {
        this.mcontext = context;
        this.mGroupName = getGName(dataDir, context.getPackageName());
        DSLogger.infos(" packagename[%s], group name[%s]", context.getPackageName(), this.mGroupName);
    }

    public String getGName(String str, String str1) {
        return a.ls(str, str1);
    }

    public File buildTargetDir(Context context, String str) {
        try {
            DSLogger.info("encoded nick[%s], origin[%s]", URLEncoder.encode(str, "utf8"), str);
            File file = new File(FileManager.newBackDirPath, snapDirName);
            a.a(file, this.mGroupName);
            File file1 = new File(file, r1);// FIXME: 2017/3/16 r1这个变量没有找到。有点尴尬
            a.a(file1, this.mGroupName);
            return file1;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }

    }

    public void checkBackFilesBeforeRecover(File file) {
        String[] list = file.list();
        DSLogger.info(" sub files :" + org.apache.commons.lang3.StringUtils.join(list, ','), new Object[0]);
        if (ArrayUtils.isEmpty(list)) {
            String str = " why there is no sub files names for dir: " + file;
            DSLogger.info(str, new Object[0]);
            try {
                throw new dataException(404, str);
            } catch (dataException e) {
                e.printStackTrace();
            }
        }
        Set hashSet = new HashSet();
        for (String add : list) {
            hashSet.add(add);
        }
        int length = list.length;
        int i = 0;
        String str;
        while (i < length) {
            String str2 = list[i];
            if (hashSet.contains(str2)) {
                i++;
            } else {
                str = " sub file not found ;" + str2;
                DSLogger.info(str, new Object[0]);
                try {
                    throw new dataException(404, str);
                } catch (dataException e) {
                    e.printStackTrace();
                }
            }
        }
        if (a.hasfile(FileManager.TBInstallPath)) {
            DSLogger.info(" sub files check ok...for :" + file, new Object[0]);
        }
        try {
            throw new dataException(404, "tb apk not exists :" + FileManager.TBInstallPath);
        } catch (dataException e) {
            e.printStackTrace();
        }
    }

    public static String LOCK_RECOVER_FOR_NETFLOW_FILE = "/data/local/tmp/recover.netflow.lock";
    public static String LOCK_RECOVER_FOR_SALE_FILE = "/data/local/tmp/recover.sale.lock";
    public static String LOCK_RECOVER_TAOBAO_FILE = "/data/local/tmp/recover.taobao.lock";
    public static String LOCK_TAKE_SNAP_TAOBAO_FILE = "/data/local/tmp/takesnap.taobao.lock";


    public boolean checkRecoveryForNetflow() {
        String str = LOCK_RECOVER_FOR_NETFLOW_FILE;
        if (hashLockFile(str)) {
            return isDeviceMatch(str);
        } else {
            DSLogger.warn(" no lock file for recover netflow", new Object[0]);
            return false;
        }
    }

    public boolean hashLockFile(String str) {
        return org.apache.commons.lang3.StringUtils.length(a.cat(str)) > 4;
    }

    public boolean isDeviceMatch(String str) {
        phoneBaseInfo.a();
        String a = phoneBaseInfo.getDeviceId(this.mcontext);
        return a.equals(JSON.parseObject(a).get(DSTopManager.HMethods.getDeviceId.name()));
    }

    public boolean toClearTbData = false;

    public void clearLeftData() {
        if (toClearTbData) {
            String[] strarr = clearDir;
        }
    }

    public void clearTargetDir(Context context, File file) {
        File file1 = null;
        DSLogger.info(" target dir :" + file.getAbsolutePath(), new Object[0]);
        if (file.exists()) {
            File[] listFiles = file.listFiles();
            DSLogger.info("sub dirs :" + org.apache.commons.lang3.StringUtils.join(file.list(), ','), new Object[0]);
            int length = listFiles.length;
            int i = 0;
            while (i < length) {
                File file2 = listFiles[i];
                DSLogger.info(" sub files :" + file2, new Object[0]);
                if (file1 != null && file2.lastModified() > file1.lastModified()) {
                    file2 = file1;
                }
                i++;
                file1 = file2;
            }
            DSLogger.info(" clear oldest file :" + file1, new Object[0]);
            if (file1 != null) {
                a.remove(file1.getAbsolutePath());
                return;
            }
            return;
        }
        file.mkdir();
    }

    public static String envSaveDir = "/data/local/tmp/env";
    public static String uidFileName = "uid";
    public static String srcTbDbPath = "databases";
    public String tbDatabasesDir = (tbDataDir + "/databases");
    public static String srcSharePrefsPath = "shared_prefs";

    public void copyCacheBack(Context context, File file1) {
        try {

            File file2 = new File(envSaveDir, uidFileName);
            if (file2.exists()) {
                String readfiletostring = FileUtils.readFileToString(file2);
                DSLogger.info(" uid [" + readfiletostring + "]file :" + file2, new Object[0]);
                if (!StringUtils.isEmpty(readfiletostring) && readfiletostring.startsWith(PushConstants.ADVERTISE_ENABLE))// FIXME: 2017/3/16 这是百度的一个包。需要引入
                {
                    a.mkdir2(tbDataDir);
                    a.chowm(readfiletostring, tbDataDir);
                    String absolutePath = file1.getAbsolutePath();
                    if (!absolutePath.endsWith("/")) {
                        absolutePath = absolutePath + "/";
                    }
                    a.copy(absolutePath + srcTbDbPath, tbDataDir);
                    a.chowm(readfiletostring, tbDatabasesDir);
                    a.copy(absolutePath + srcSharePrefsPath, tbDataDir);
                    a.chowm(readfiletostring, tbSharePrefsDir);
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            try {
                throw new dataException(500, "io error :" + e.getMessage());
            } catch (dataException e1) {
                e1.printStackTrace();
            }
        }

    }

    public void copyCacheData(File file1) {
        try {
            String gName = getGName(dataDir, tbPackageName);
            DSLogger.info(" origin tb user group name :" + gName, new Object[0]);
            if (!StringUtils.isEmpty(gName) && gName.startsWith(PushConstants.ADVERTISE_ENABLE)) {
                File file2 = new File(envSaveDir, uidFileName);
                a.chowm(this.mGroupName, file2.getAbsolutePath());
                a.c(" chmod 777 " + file2.getAbsolutePath());
                FileUtils.write(file2, gName);
            }
            String absolutePath = file1.getAbsolutePath();
            if (!StringUtils.isEmpty(absolutePath)) {
                a.copy(tbDatabasesDir, absolutePath);
                a.copy(tbSharePrefsDir, absolutePath);
                a.chowm(this.mGroupName, absolutePath);
                a.c(" chmod -R 777" + absolutePath);
            }

        } catch (Exception e) {
            DSLogger.error(e, e.getMessage(), new Object[0]);
            e.printStackTrace();
        }
    }

    public static String srcDataPath = "/data/com.taobao.taobao";
    public static String commStoragePath = "/data/local/tmp/storage";
    public static String srcSDCardPath = "/sdcard/com.taobao.taobao";
    public static String srcObbPath = "/obb/com.taobao.com";
    public static String OUTPUT_LOGIN_SUCCESS = "_tb_login_success_";
    public static String ROOT_NAME = "root";
    public static String SDCARD_RW_NAME = "sdcard_rw";
    public static String SYSTEM_NAME = "system";
    public static String backupSettingsDbFile = "bak.settings.db";
    public static String originSettingsDbPath = "/data/data/com.android.providers.settings/databases/settings.db";
    public static String imeiFileName = "imei";
    public static String deviceConfigFile = "deviceConfig.json";

    public void copyDataBack(Context context, File file1) {
        try {
            File file2 = new File(file1, uidFileName);
            String b = a.cat(file2.getAbsolutePath());
            if (!StringUtils.isEmpty(b)) {
                b = b.trim().replace("%0A", StringUtils.EMPTY);
            }
            DSLogger.info(" uid [" + b + "]file :" + file2, new Object[0]);
            a.copy(new File(file1, srcDataPath).getAbsolutePath(), tbDataDir);
            a.copy(commStoragePath, tbStorageRelativePath);
            a.chowm(b, tbDataDir);
            a.copy(new File(file1, srcSDCardPath).getAbsolutePath(), tbSdcardDpDir);
            a.copy(new File(file1, srcObbPath).getAbsolutePath(), tbObbDir);
            a.chown(ROOT_NAME, SDCARD_RW_NAME, tbSDCardDir);
            b = new File(file1, backupSettingsDbFile).getAbsolutePath();
            if (new File(b).exists()) {
                a.copy(b, originSettingsDbPath);
                a.chowm(SYSTEM_NAME, originSettingsDbPath);
            }
            a.c(" chown system:system " + originSettingsDbPath);
            a.c(" chmod 660 " + originSettingsDbPath);
        } catch (Exception e) {
            DSLogger.error(e, e.getMessage(), new Object[0]);
            try {
                throw new dataException(500, " io error :" + e.getMessage());
            } catch (dataException e1) {
                e1.printStackTrace();
            }
        }
    }

    public void copyDataForward(File file) {
        try {
            if (toClearTbData) {
                a.c(String.format(" rm -r %s", new Object[]{tbDataDir + tbStorageRelativePath}));
            }
            String gName = getGName(dataDir, tbPackageName);
            DSLogger.info(" origin tb user group name :" + gName, new Object[0]);
            String str = file + "/uid";
            a.a(str, gName);
            a.c("chmod 777 " + str);
            gName = file + "/data/";
            a.mkdir(gName);
            a.copy(tbSDCardDir, gName);
            a.copy(tbSdcardDpDir, gName);
            gName = file + "/sdcard/";
            a.mkdir(gName);
            a.copy(tbSDCardDir, gName);
            a.copy(tbSdcardDpDir, gName);
            a.chowm(this.mGroupName, gName);
            gName = file + "/obb/";
            a.mkdir(gName);
            a.copy(tbObbDir, gName);
            a.chowm(this.mGroupName, gName);
            JSONObject fetchvalues = DSParams.fetchValues();
            str = fetchvalues.getString(HMethods.getDeviceId.name());
            String absolutePath = new File(file, imeiFileName).getAbsolutePath();
            a.a(absolutePath, str);
            a.chowm(this.mGroupName, str);
            str = new File(file, deviceConfigFile).getAbsolutePath();
            a.a(str, fetchvalues.toString());
            a.chowm(this.mGroupName, str);
            gName = new File(file, "bak.settings.db").getAbsolutePath();
            a.copy(originSettingsDbPath, gName);
            a.chowm(this.mGroupName, gName);

        } catch (Exception e) {
            DSLogger.error(e, e.getMessage(), new Object[0]);

        }
    }

    /**
     *
     */
    public void ensureTBStorage() {
        if (countSubFiles(commStoragePath) > 3) {
            DSLogger.info(" comm storage file exist skip..", new Object[0]);
            return;
        }
        a.copy(tbDataDir + tbStorageRelativePath, commStoragePath);
        a.chowm(this.mGroupName, commStoragePath);
    }

    /**
     * 查找最近的目录
     *
     * @param file
     * @return
     */
    public File findLatestDir(File file) {
        File file1 = null;
        File[] listfiles = file.listFiles();
        if (ArrayUtils.isEmpty(listfiles)) {
            try {
                throw new dataException(404, "no sub files for :" + file);
            } catch (dataException e) {
                e.printStackTrace();
            }
        }
        int length = listfiles.length;
        int i = 0;
        while (i < length) {
            File file2 = listfiles[i];
            DSLogger.info(" file :" + file2 + " with latest :" + new Date(file2.lastModified()), new Object[0]);
            if (file1 != null && file2.lastModified() <= file1.lastModified()) {
                file2 = file1;
            }
            i++;
            file1 = file2;
        }
        return file1;
    }

    /**
     * 获取一个dssnapshot的实例
     *
     * @param context
     * @return
     */
    public static DSSnapshotManager getInstance(Context context) {
        if (_instance != null) {
            if (!(context == null || _instance.mcontext == context)) {
                _instance.mcontext = context;
            }
            return _instance;
        }
        DSSnapshotManager dsSnapshotManager = new DSSnapshotManager(context);
        _instance = dsSnapshotManager;
        return dsSnapshotManager;
    }

    /**
     * 这应该是把设备的信息写入的一个类
     *
     * @param context
     */
    private void writeRandomDeviceConfig(Context context) {
        SimulateData.init(context);
        JSONObject fetchValues = DSParams.fetchValues();
        HashMap oneMap = SimulateData.getOneMap();
        fetchValues.put(HMethods.getDeviceId.name(), SimulateData.genImei((String) oneMap.get(HMethods.getDeviceId.name())));
        Object obj = (String) oneMap.get(HMethods.BRAND.name());
        fetchValues.put(HMethods.BRAND.name(), obj);
        fetchValues.put(HMethods.MANUFACTURER.name(), obj);
        fetchValues.put(HMethods.HARDWARE.name(), obj);
        Object obj2 = (String) oneMap.get(HMethods.MODEL.name());
        fetchValues.put(HMethods.DEVICE.name(), ((String) obj + obj2));
        fetchValues.put(HMethods.MODEL.name(), obj2);
        fetchValues.put(HMethods.PRODUCT.name(), obj2);
        fetchValues.put(HMethods.FINGERPRINT.name(), (String) oneMap.get(HMethods.FINGERPRINT.name()));
        int nextInt = rand.nextInt(2);
        fetchValues.put(HMethods.getSimSerialNumber.name(), SimulateData.getSimSerial(nextInt));
        fetchValues.put(HMethods.getSubscriberId.name(), SimulateData.getSubscriberId(nextInt));
        fetchValues.put(HMethods.ANDROID_ID.name(), SimulateData.genRandAndroidId());
        fetchValues.put(HMethods.getMacAddress.name(), SimulateData.getMac());
        fetchValues.put(HMethods.getBSSID.name(), SimulateData.getMac());
        fetchValues.put(HMethods.getSSID.name(), SimulateData.genRandSSID());
        fetchValues.put(HMethods.getLine1Number.name(), StringUtils.EMPTY);
        DSParams.writeAndSave(context, fetchValues);
    }


    public String backupCurrTBEnv(Context context, String str) {
        return null;
    }

    public void checkRestartLock() {
        if (!hashLockFile(LOCK_RECOVER_FOR_NETFLOW_FILE)) {
            if (hashLockFile(LOCK_RECOVER_FOR_NETFLOW_FILE)) {
                checkRecoveryForNetflow();
            }
        } else if (hashLockFile(LOCK_TAKE_SNAP_TAOBAO_FILE)) {
            createSnapshotLoginAfterRestart();
        }
    }

    public void createSnapshotLoginAfterRestart() {
        try {
            String b = a.cat(LOCK_TAKE_SNAP_TAOBAO_FILE);
            if (org.apache.commons.lang3.StringUtils.isBlank(b)) {
                DSLogger.error(" no content read from :" + LOCK_TAKE_SNAP_TAOBAO_FILE, new Object[0]);
                return;
            }
            TestAccountBean bean = JSON.parseObject(b, TestAccountBean.class);
            String realname = bean.getAccountBean().getRealname();
            b = bean.getAccountBean().getRealPswd();
            b = a.c(CMD_LOGIN_TAOBAO + (" -e name " + URLEncoder.encode(realname, a.b) + " -e pswd " + URLEncoder.encode(b, a.b)));
            DSLogger.info(" login taobao res :" + b, new Object[0]);
            boolean z = b != null && b.contains(OUTPUT_LOGIN_SUCCESS);
            DSLogger.info(" login success??? :" + z, new Object[0]);
            if (z) {
                takeSnapShot(realname);
            }


        } catch (Exception e) {
            DSLogger.error(e, e.getMessage(), new Object[0]);
        }
    }

    public static int pid = Process.myPid();

    public void takeSnapShot(String str) {
        try {
            DSLogger.info(" with current pid :" + pid, new Object[0]);
            if (toClearTbData) {
                DSLogger.info(" uninstall taobao res:" + a.c(" pm uninstall -k com.taobao.taobao"), new Object[0]);
            }
            File file = new File(buildTargetDir(this.mcontext, str), "12135");
            a.a(file, this.mGroupName);
            DSLogger.info(" make nick+ts dir :" + file.getAbsolutePath(), new Object[0]);
            copyDataForward(file);
        } catch (Exception e) {

        }
    }

    public int countSubFiles(String str) {
        String c = a.c(String.format(" ls -al %s", new Object[]{str}));
        return org.apache.commons.lang3.StringUtils.isBlank(c) ? 0 : c.split("\\n").length;
    }

    static String[] LOCK_FILES = new String[]{LOCK_TAKE_SNAP_TAOBAO_FILE, LOCK_RECOVER_TAOBAO_FILE, LOCK_RECOVER_FOR_NETFLOW_FILE, LOCK_RECOVER_FOR_SALE_FILE};

    public void clearAllTheLocks() {
        for (String str : LOCK_FILES) {
            DSLogger.info("rm lock file :" + str, new Object[0]);
            a.remove(str);
        }

    }

    public void clearTbData() {
        for (String str : clearDir) {
            a.remove(str);
        }
    }

    public void clearTmpData() {
        for (String str : tmpFile) {
            a.remove(str);
        }
    }

    /**
     * 统计所有文件数量
     *
     * @param str
     * @return
     */
    int coutSubFiles(String str) {
        String c = a.c(String.format(" ls -al %s", new Object[]{str}));
        return org.apache.commons.lang3.StringUtils.isBlank(c) ? 0 : c.split("\\n").length;
    }

    public void createSnapshotAfterLogin() {

    }

    public void debugUIAutomatorOutput() {
        DSLogger.info(" exec res >>>>>>>>>>>>>>>>>>:" + a.c(CMD_RESULT_OUTPUT), new Object[0]);
    }

    /**
     * 重启后重新执行autorunner
     */
    public void execNetflowTaskAfterRestart() {
        String b = a.cat(LOCK_RECOVER_FOR_NETFLOW_FILE);
        rebuildTBRecoveryEnv(LOCK_RECOVER_FOR_NETFLOW_FILE);
        b = JSON.parseObject(b, TestAccountBean.class).getAccountBean().getRealname();
        a.c(CMD_NETFLOW_RECOVER);
        takeSnapShot(b);

    }


    /**
     * 通过重新安装淘宝，重建淘宝环境
     *
     * @param str
     * @return
     */
    public boolean rebuildTBRecoveryEnv(String str) {
        String b = a.cat(LOCK_RECOVER_TAOBAO_FILE);
        DSLogger.info(" content :" + b, new Object[0]);
        if (StringUtils.isEmpty(b) || b.length() < 4) {
            DSLogger.info("no snapshot file  back", new Object[0]);
            return false;
        }
        phoneBaseInfo.a();
        b = phoneBaseInfo.getPhoneNumber(this.mcontext);
        DSLogger.info("curr imei[%s], expected imei[%s]", b, JSON.parseObject(b).get(DSTopManager.HMethods.getDeviceId.name()).toString());
        if (!b.equals(JSON.parseObject(b).get(DSTopManager.HMethods.getDeviceId.name()).toString())) {
            return false;
        }x
        DSLogger.info(" taobao apk install res :" + a.installTaobao(), new Object[0]);
        return true;
    }

    public boolean hasLockFile() {
        return org.apache.commons.lang3.StringUtils.length(a.cat(LOCK_RECOVER_TAOBAO_FILE)) > 4;
    }

    public boolean hasLockFile(String str) {
        return org.apache.commons.lang3.StringUtils.length(a.cat(str)) > 4;
    }

    /**
     * 查找是否有旺旺的缓存
     * @param str
     * @return
     */
    public boolean hasWangwangCache(String str) {
        try {
            String replace = URLEncoder.encode(str, "UTF-8").replace("+", "%20");
            if (new File(envSaveDir, replace).exists()) {
                return true;
            }
            DSLogger.error("wangwang[" + replace + "] has no cache !!! ", new Object[0]);
            return false;
        } catch (Throwable e) {
            DSLogger.error(e, e.getMessage(), new Object[0]);
            return false;
        }
    }

    public File[] listNickSnaps(Context context, String str) {
        File buildTargetDir = buildTargetDir(context, str);
        return !buildTargetDir.exists() ? new File[0] : buildTargetDir.listFiles();
    }


    public void recoverLatestSnapshot(String str) {
        try {
            copyDataBack(this.mcontext, findLatestDir(buildTargetDir(this.mcontext, str)));
        } catch (Throwable e) {
            DSLogger.error(e, e.getMessage(), new Object[0]);
        }
    }

    public void recoverWangwangSnapshot(String str) {
        try {
            String replace = URLEncoder.encode(str, "UTF-8").replace("+", "%20");
            File file = new File(envSaveDir, replace);
            if (file.exists()) {
                DSLogger.info(" start to copy wangwang[" + replace + "] cache back...", new Object[0]);
                copyCacheBack(this.mcontext, file);
                return;
            }
            DSLogger.error("wangwang[" + replace + "] has no cache !!! ", new Object[0]);
        } catch (Throwable e) {
            DSLogger.error(e, e.getMessage(), new Object[0]);
        }
    }

    public void startSnapshotCreator(Context context) {
        clearAllTheLocks();
        writeRandomDeviceConfig(context);
        a.a(LOCK_TAKE_SNAP_TAOBAO_FILE, JSON.toJSONString(TestAccountBean.gettestbean()));
    }


    public void takeWangwangShot(String str) {
        try {
            DSLogger.info(" start to take wangwang[" + str + "] shot...", new Object[0]);
            File file = new File(envSaveDir, URLEncoder.encode(str, "UTF-8").replace("+", "%20"));
            a.a(file, this.mGroupName);
            a.c(" chmod 777 " + file);
            DSLogger.info(" make nick+ts dir :" + file.getAbsolutePath(), new Object[0]);
            copyCacheData(file);
        } catch (Throwable e) {
            DSLogger.error(e, e.getMessage(), new Object[0]);
        }
    }




}
